package cn.huihuo.weibo.module;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * Created by Administrator on 2015/8/27.
 */
public class Message extends Model<Message> {
    public static final Message dao = new Message();

    /**
     * 使用userId获取所有信息
     * @param pageNumber
     * @param pageSize
     * @param userId
     * @return
     */
    public Page<Message> findProductCommentBuyProdId(int pageNumber, int pageSize, String userId){
        return paginate(pageNumber, pageSize, "select * ", "from message where user_id = ? order by is_read, write_time desc", userId);
    }

    public Message findUnReadTotal(String userId){
        return findFirst("select count(1) size from message t where t.user_id=? and t.is_read=0",userId);
    }

    public int deleteMessage(Integer id){
        return Db.update("delete from  message where reply_id=? ",id);
    }
}
